package com.tensquare.qa.dao;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @Description: 数据访问接口
 * @Author: xuxiaoyu
 * @Create: 2019-11-20 22:52
 */
public interface ProblemDao extends JpaRepository<Problem, String>, JpaSpecificationExecutor<Problem> {

    /**
     * 根据标签ID查询最新问题列表 使用更新时间倒序排序
     */
    @Query(value = "SELECT * FROM tb_problem WHERE id in(SELECT problemid FROM tb_pl WHERE labelid=?) ORDER BY updatetime DESC", nativeQuery = true)
    public Page<Problem> findNewListByLabelId(String labelId, Pageable pageable);
    /**
     * 根据标签ID查询热门问题列表 使用回复数倒序排序
     */
//    @Query("select p from Problem p where id in( select problemid from Pl where labelid=?1 ) order by reply desc")
    @Query(value = "SELECT * FROM tb_problem WHERE id in (SELECT problemid FROM tb_pl WHERE labelid=?)  ORDER BY reply DESC", nativeQuery = true)
    public Page<Problem> findHotListByLabelId(String labelId,Pageable pageable);
    /**
     * 根据标签ID查询等待回答列表
     */
    @Query(value = "select * from tb_problem where id in (select problemid from tb_pl where labelid=?) and reply=0 order by createtime desc",nativeQuery = true)
    public Page<Problem> findWaitListByLabelId(String labelId,Pageable pageable);
}
